<?php
namespace  app\admin\controller;

use app\admin\model\AuthGroup;
use app\admin\model\AuthRule;
use app\BaseController;
use think\facade\Request;
use think\facade\View;

//权限页
class Auth extends BaseController {
    //auth 权限列表
    public function auth(){
        $list=AuthRule::authListInfo();
        View::assign('list',$list);
        return View::fetch();
    }
    //auth 权限添加
    public function addMenu(){
        if (Request::isPost()){
            $post=Request::post();
            $res=AuthRule::authAddInfo($post);
            if ($res){
                $this->success('添加成功',url('auth/auth'));
            }else{
                $this->error('添加失败');
            }
        }else{
            return View::fetch();
        }
    }
    //auth 权限修改
    public function editMenu(){
        $param=Request::param();
        if (Request::isPost()){
          $res=AuthRule::authEditInfo($param);
          if ($res){
              $this->success('修改成功',url('auth/auth'));
          }else{
              $this->error('修改失败');
          }
        }else{
            $find=AuthRule::authEditInfo($param);
            View::assign($find->toArray());
            return View::fetch();
        }


    }
    //auth 权限删除
     public function delMenu(){
        $get=Request::get();
        $res=AuthRule::authDelInfo($get);
        if ($res){
            $this->success('删除成功',url('auth/auth'));
        }else{
            $this->error('删除失败');
        }

      }




      //authGroup  权限组列表
     public function authGroup(){
        $list=AuthGroup::authGroupInfo();
        View::assign('list',$list);
        $rule=AuthGroup::authGroupAddInfo([]);
        View::assign('rule',$rule);
         return View::fetch();
      }
     //authGroup  权限组添加
     public function authGroupAdd(){
        if (Request::isPost()){
        $post=Request::post();
        $post['rules']=implode(",", $post['rules']);
        $res=AuthGroup::authGroupAddInfo($post);
        if ($res){
            $this->success('添加成功',url('auth/authGroup'));
        }else{
            $this->error('添加失败');
        }
        }else{
            return View::fetch();
        }
      }
      //authGroup   权限组修改
     public function authGroupEdit(){
        $param=Request::param();
        if (Request::isPost()) {
            $param['rules']=implode(",", $param['rules']);
            $res=AuthGroup::authGroupEditInfo($param);
            if ($res){
                $this->success('修改成功',url('auth/authGroup'));
            }else{
                $this->error("修改失败");
            }
        }else{
            $find=AuthGroup::authGroupEditInfo($param);
            $find['rules']=explode(',', $find['rules']);
            View::assign($find);
            $rule=AuthGroup::authGroupAddInfo([]);
            View::assign('rule',$rule);
            return View::fetch();
        }


      }

      //authGroup   权限组删除
     public function authGroupDel(){
        $get=Request::get();
        $res=AuthGroup::authGroupDelInfo($get);
        if ($res){
            $this->success('删除成功',url('auth/authGroup'));
        }else{
            $this->error('删除失败');
        }

      }



}